#include "Emotion.h"
#include <QPainter>
#include <QDebug>

Emotion::Emotion(QWidget* parent) :
	MoveableItem(parent),
	_type(EmotionType()),
	_extended(false)
{
}


void Emotion::setEmotion(EmotionType type)
{
	_type = type;
}

bool Emotion::isExtended()
{
	return _extended;
}

EmotionType Emotion::type()
{
	return _type;
}

void Emotion::setExtended(bool extend)
{
	if(_extended == extend) return;

	_extended = extend;

	if(_extended){
		setPosition(_x0 - _width/2, _y0 - _height/2);
		setRect(_width + _width, _height + _height);
	}
	else{
		setPosition(_x0 + _width/4, _y0 + _height/4);
		setRect(_width - _width/2, _height - _height/2);
	}
}

void Emotion::paintEvent(QPaintEvent* event)
{
	QPainter painter(this);

	painter.setRenderHint(QPainter::Antialiasing, true);

	if(_type._type == EmotionType::None){
		painter.setBrush(QBrush(_type.getColor()));
		painter.drawEllipse(2,2,_width-4,_height-4);
	}
	else{
		painter.drawPixmap(0,0,_width,_height,QPixmap(_type.getRes()));
	}

	painter.end();
}
